package controllers

import (
	"xxp_api/models"

	"github.com/astaxie/beego"
	//"github.com/astaxie/beego/logs"
)

// 用户相关接口
type OrderController struct {
	beego.Controller
}

// @Summary 订单管理
// @Description 订单管理
// @Param	uid 		    query 	int	true	 "用户id"
// @Param	types 		query 	int	true	 "类型1兑换券，2线上商品，3线下课程"
// @Param	status 	    query 	int	true	 "订单状态，0全部，1未支付，2已支付，3已取消"
// @Param	keystart 	    query 	int	true	 "分页参数"
// @Success 200 {object} models.Response
// @router /list [post]
func (u *OrderController) List() {
	var ret models.Response
	uid, _ := u.GetInt("uid")
	types, _ := u.GetInt("types")
	status, _ := u.GetInt("status")
	keystart, _ := u.GetInt("keystart")
	beego.Debug(u.Ctx.Request.Form)
	if types <= 0 || status < 0 || uid <= 0 {
		ret.Code = models.ERRCODE_PARAMS_ERROR
		ret.Msg = "参数错误"
	} else {
		ret = models.OrderList(uid, types, status, keystart)
	}

	u.Data["json"] = ret
	u.ServeJSON()
}

// @Summary 订单统计
// @Description 订单统计
// @Param	uid 		    query 	int	true	 "用户id"
// @Param	types 		query 	int	true	 "类型0全部，1兑换券，2线上商品，3线下课程"
// @Param	time 	    query 	int	true	 "时间范围，1本月，2本周，3最近30天"
// @Success 200 {object} models.Response
// @router /statistic [post]
func (u *OrderController) Statistic() {
	var ret models.Response
	uid, _ := u.GetInt("uid")
	types, _ := u.GetInt("types")
	time, _ := u.GetInt("time")
	beego.Debug(u.Ctx.Request.Form)
	if types < 0 || time < 0 || uid <= 0 {
		ret.Code = models.ERRCODE_PARAMS_ERROR
		ret.Msg = "参数错误"
	} else {
		ret = models.OrderStatistic(uid, types, time)
	}

	u.Data["json"] = ret
	u.ServeJSON()
}
